//
//  Country.m
//  ImGuider
//
//  Created by llt on 2017/4/24.
//  Copyright © 2017年 imguider. All rights reserved.
//

#import "Country.h"

@implementation Country

+ (NSDictionary *)modelCustomPropertyMapper {
    
    return @{@"cid" : @"id"};
}

+ (NSDictionary *)modelContainerPropertyGenericClass {
    
    return @{@"cities" : [City class]};
}


- (NSString *)smartName {
    
    NSString *name = @"";
    
    switch (AppManager.sharedManager.language) {
        case AppLanguageCNJan:
            
            name = _name ? _name : _country;
            break;
        case AppLanguageCNFan:
        case AppLanguageCNFanXG:
            
            name = _fname;
            break;
        case AppLanguageJapanese:
            
            name = _jname;
            break;
        default:
            
            name = _ename;
            break;
    }
    
    if (name.length == 0) {
        name = _ename ? _ename : _country;
    }
    
    if (name.length == 0) {
        name = _ename ? _ename : _name;
    }
    return name;
}

- (NSArray *)citiesSortArray {
    
   return [self.cities sortedArrayUsingComparator:^NSComparisonResult(City *obj1, City *obj2) {
        
       return [[IGUtil firstCharactor:obj1.smartName] compare:[IGUtil firstCharactor:obj2.smartName]];
    }];
}

@end
